/**
 * Apr 23, 2010
 */
package org.tomale.id.projects.ui.wizards;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.tomale.id.projects.Activator;

/**
 * @author ferd
 *
 */
public class ProjectOverviewPage extends WizardPage {

	public static final String PAGE_TITLE = "New Project";
	public static final String PAGE_TEXT = "General Information";
	public static final String PAGE_DESC = "General information about the project.";
	
	Text _name;
	Text _desc;
	
	ModifyListener _modify = new ModifyListener() {
		
		@Override
		public void modifyText(ModifyEvent e) {
			updatePageComplete();
		}
	};
	
	public ProjectOverviewPage(){
		super(PAGE_TITLE,
				PAGE_TEXT,
				Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, 
				"icons/edit.png"));
		setDescription(PAGE_DESC);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(Composite parent) {
		Composite comp = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		comp.setLayout(layout);
		
		Label l;
		
		// name
		l = new Label(comp, SWT.NONE);
		l.setText("&Name");
		l.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
	
		_name = new Text(comp, SWT.BORDER);
		_name.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));
		_name.addModifyListener(_modify);

		// description
		l = new Label(comp, SWT.NONE);
		l.setText("&Description");
		l.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
	
		_desc = new Text(comp, SWT.BORDER | SWT.MULTI);
		_desc.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
		_desc.addModifyListener(_modify);

		setControl(comp);
		
		_name.setFocus();
	}

	@Override
	public boolean isPageComplete() {
		return !_name.getText().isEmpty() && !_desc.getText().isEmpty();
	}
	
	private void updatePageComplete(){
		setPageComplete(isPageComplete());
	}

	public String getProjectName(){
		return _name.getText();
	}
	
	public String getProjectDescription(){
		return _desc.getText();
	}
}
